package com.sxsihe.heartmate.util;


//  Decompiled by jdec
//  DECOMPILER HOME PAGE: jdec.sourceforge.net
//  Main HOSTING SITE: sourceforge.net
//  Copyright (C)2006,2007,2008 Swaroop Belur.
//  jdec comes with ABSOLUTELY NO WARRANTY;
//  This is free software, and you are welcome to redistribute
//  it under certain conditions;
//  See the File 'COPYING' For more details.




public class RawDataArray {
    private static int BUFFER_SIZE_HPF = 257;
    private static int BUFFER_SIZE_LPF = 131;
    private static float[] array;
    public static int arrayLength;
    private static float baseLine;
    private static float bottomBorde;
    private static int bufferCounter;
    private static float[] eegBuffer_hpf;
    private static float[] eegBuffer_lpf;
    private static float egoRawData;
    private static double[] filt_coeff_hpf;
    private static double[] filt_coeff_lpf;
    private static float filtered;
    private static float[] quiteArray;
    public static int rawData;
    private static float rawMax;
    private static float scaleRate;
    public static Object syncRoot;
    private static float[] tempeegBuffer_hpf;
    private static float[] tempeegBuffer_lpf;
    private static float topBorde;

    static {
        eegBuffer_lpf = new float[BUFFER_SIZE_LPF];
        tempeegBuffer_lpf = new float[BUFFER_SIZE_LPF];
        eegBuffer_hpf = new float[BUFFER_SIZE_HPF];
        tempeegBuffer_hpf = new float[BUFFER_SIZE_HPF];
        bufferCounter = 0;
        filt_coeff_lpf = new double[]{-1.68667856880048E-4D, -3.29491866181245E-4D, -5.70063232930836E-4D, -8.26612236151652E-4D, -0.00102118556820869D, -0.00104971174571026D, -8.01872594340795E-4D, -1.90414912607982E-4D, 8.15951956596345E-4D, 0.00216436484902995D, 0.00370511679981089D, 0.00520177157607237D, 0.00636721899187339D, 0.00692217086219052D, 0.00666504229086917D, 0.00553570513970002D, 0.0036561554436569D, 0.00133045289849665D, -0.00100139139502655D, -0.00285231859315746D, -0.00380222871588756D, -0.00361049462064574D, -0.00229679878806854D, -1.63357055355674E-4D, 0.00225439311612249D, 0.00430512184469986D, 0.00538302387765288D, 0.0050948619038306D, 0.00338731613829165D, 5.95295172245412E-4D, -0.00261147051358666D, -0.00537969180920409D, -0.00689102492163201D, -0.00659400949694251D, -0.00438666736300679D, -6.9322820676908E-4D, 0.0035980779193214D, 0.00733374168470104D, 0.00939005097377244D, 0.00899234291229742D, 0.00597232020008678D, 8.84686973420358E-4D, -0.00506484158461425D, -0.0102813959951347D, -0.0131816190779121D, -0.0126385734098676D, -0.00835374322437216D, -0.0010463658426189D, 0.00761264761084114D, 0.0153341832929977D, 0.0197543126832424D, 0.0190691382092526D, 0.0126064198256393D, 0.0011805929005385D, -0.0128825259120617D, -0.0260922278266422D, -0.0344634703045011D, -0.0343808963219089D, -0.0234687806909481D, -0.00126440351872214D, 0.0304747159292722D, 0.0679240217134153D, 0.105798489688712D, 0.138301661077912D, 0.160224410855649D, 0.167961155238185D, 0.160224410855649D, 0.138301661077912D, 0.105798489688712D, 0.0679240217134153D, 0.0304747159292722D, -0.00126440351872214D, -0.0234687806909481D, -0.0343808963219089D, -0.0344634703045011D, -0.0260922278266422D, -0.0128825259120617D, 0.0011805929005385D, 0.0126064198256393D, 0.0190691382092526D, 0.0197543126832424D, 0.0153341832929977D, 0.00761264761084114D, -0.0010463658426189D, -0.00835374322437216D, -0.0126385734098676D, -0.0131816190779121D, -0.0102813959951347D, -0.00506484158461425D, 8.84686973420358E-4D, 0.00597232020008678D, 0.00899234291229742D, 0.00939005097377244D, 0.00733374168470104D, 0.0035980779193214D, -6.9322820676908E-4D, -0.00438666736300679D, -0.00659400949694251D, -0.00689102492163201D, -0.00537969180920409D, -0.00261147051358666D, 5.95295172245412E-4D, 0.00338731613829165D, 0.0050948619038306D, 0.00538302387765288D, 0.00430512184469986D, 0.00225439311612249D, -1.63357055355674E-4D, -0.00229679878806854D, -0.00361049462064574D, -0.00380222871588756D, -0.00285231859315746D, -0.00100139139502655D, 0.00133045289849665D, 0.0036561554436569D, 0.00553570513970002D, 0.00666504229086917D, 0.00692217086219052D, 0.00636721899187339D, 0.00520177157607237D, 0.00370511679981089D, 0.00216436484902995D, 8.15951956596345E-4D, -1.90414912607982E-4D, -8.01872594340795E-4D, -0.00104971174571026D, -0.00102118556820869D, -8.26612236151652E-4D, -5.70063232930836E-4D, -3.29491866181245E-4D, -1.68667856880048E-4D};
        filt_coeff_hpf = new double[]{0.0240815539286682D, 9.40715897598692E-4D, 9.5643797019856E-4D, 9.69697411452199E-4D, 9.8146855754746E-4D, 9.9037312341015E-4D, 9.98045343290508E-4D, 0.00100268670736766D, 0.00100598820112366D, 0.00100617210221234D, 0.00100502904982186D, 0.00100065530537616D, 9.94844991789253E-4D, 9.8556811727289E-4D, 9.74759111683958E-4D, 9.60406141450635E-4D, 9.44617219923473E-4D, 9.25316284579598E-4D, 9.04056377730812E-4D, 8.78031076317816E-4D, 8.52364630674893E-4D, 8.2073414158823E-4D, 7.8737089428539E-4D, 7.50166173221365E-4D, 7.11117897876378E-4D, 6.66784641103747E-4D, 6.20928846705191E-4D, 5.69590780355754E-4D, 5.1729620911614E-4D, 4.59227877785015E-4D, 4.00845175023879E-4D, 3.36300741790042E-4D, 2.72561315287353E-4D, 2.02258572689728E-4D, 1.34512503466984E-4D, 5.89249946345925E-5D, -1.20066664151013E-5D, -9.54404000307032E-5D, -1.71944683771412E-4D, -2.90310451521375E-4D, -3.71282599646329E-4D, -4.52216060042622E-4D, -5.61446979520252E-4D, -6.56668952699643E-4D, -7.65592161135481E-4D, -8.6952609872032E-4D, -9.83158115535796E-4D, -0.0010941426335667D, -0.00121295233934373D, -0.00133034468479231D, -0.00145448666649568D, -0.00157784742816918D, -0.00170707020704287D, -0.00183582932898464D, -0.00196982297031473D, -0.00210375948260535D, -0.00224256100571596D, -0.00238157936428058D, -0.00252355494007084D, -0.00266782132560331D, -0.00281525361822139D, -0.00296157940918263D, -0.00311319492784397D, -0.00326476953978251D, -0.00341959839388502D, -0.00357414107030067D, -0.00373163176685477D, -0.00388890484967938D, -0.00404868980405557D, -0.00420804768477047D, -0.00436928973880953D, -0.00453000935081191D, -0.00469232334515239D, -0.00485459722634887D, -0.00501848163395221D, -0.00518296598466496D, -0.00534825870102164D, -0.00551367239946968D, -0.0056736504539968D, -0.00583360450713192D, -0.00600481134200426D, -0.00616243992601246D, -0.00632676244108102D, -0.00648634040190837D, -0.00664813846220241D, -0.00680598282166261D, -0.00696522085580777D, -0.00712075629715319D, -0.00727699561591129D, -0.00742942902665456D, -0.00758198103611988D, -0.00773067849034757D, -0.00787907548502928D, -0.00802359020324072D, -0.00816723470663195D, -0.00830689473773286D, -0.00844489538766136D, -0.00858023292024476D, -0.00871282911154019D, -0.00883991541333595D, -0.00896897779490221D, -0.00909076121376995D, -0.00921091543711421D, -0.00932572242967724D, -0.00943925031073509D, -0.00954712158160808D, -0.00965307023010072D, -0.00975297377184424D, -0.00985067690793729D, -0.00994238332527418D, -0.0100319523396413D, -0.0101155472657584D, -0.010196757661607D, -0.0102714992623429D, -0.0103432511790072D, -0.0104080133584448D, -0.0104698462066671D, -0.0105264232534087D, -0.0105824561216737D, -0.0106254656477531D, -0.0106698240075694D, -0.0107071317996993D, -0.0107401875728401D, -0.0107673615340736D, -0.0107908375550297D, -0.0108080232455876D, -0.0108214089326342D, -0.0108283613423595D, 0.989168433849746D, -0.0108283613423595D, -0.0108214089326342D, -0.0108080232455876D, -0.0107908375550297D, -0.0107673615340736D, -0.0107401875728401D, -0.0107071317996993D, -0.0106698240075694D, -0.0106254656477531D, -0.0105824561216737D, -0.0105264232534087D, -0.0104698462066671D, -0.0104080133584448D, -0.0103432511790072D, -0.0102714992623429D, -0.010196757661607D, -0.0101155472657584D, -0.0100319523396413D, -0.00994238332527418D, -0.00985067690793729D, -0.00975297377184424D, -0.00965307023010072D, -0.00954712158160808D, -0.00943925031073509D, -0.00932572242967724D, -0.00921091543711421D, -0.00909076121376995D, -0.00896897779490221D, -0.00883991541333595D, -0.00871282911154019D, -0.00858023292024476D, -0.00844489538766136D, -0.00830689473773286D, -0.00816723470663195D, -0.00802359020324072D, -0.00787907548502928D, -0.00773067849034757D, -0.00758198103611988D, -0.00742942902665456D, -0.00727699561591129D, -0.00712075629715319D, -0.00696522085580777D, -0.00680598282166261D, -0.00664813846220241D, -0.00648634040190837D, -0.00632676244108102D, -0.00616243992601246D, -0.00600481134200426D, -0.00583360450713192D, -0.0056736504539968D, -0.00551367239946968D, -0.00534825870102164D, -0.00518296598466496D, -0.00501848163395221D, -0.00485459722634887D, -0.00469232334515239D, -0.00453000935081191D, -0.00436928973880953D, -0.00420804768477047D, -0.00404868980405557D, -0.00388890484967938D, -0.00373163176685477D, -0.00357414107030067D, -0.00341959839388502D, -0.00326476953978251D, -0.00311319492784397D, -0.00296157940918263D, -0.00281525361822139D, -0.00266782132560331D, -0.00252355494007084D, -0.00238157936428058D, -0.00224256100571596D, -0.00210375948260535D, -0.00196982297031473D, -0.00183582932898464D, -0.00170707020704287D, -0.00157784742816918D, -0.00145448666649568D, -0.00133034468479231D, -0.00121295233934373D, -0.0010941426335667D, -9.83158115535796E-4D, -8.6952609872032E-4D, -7.65592161135481E-4D, -6.56668952699643E-4D, -5.61446979520252E-4D, -4.52216060042622E-4D, -3.71282599646329E-4D, -2.90310451521375E-4D, -1.71944683771412E-4D, -9.54404000307032E-5D, -1.20066664151013E-5D, 5.89249946345925E-5D, 1.34512503466984E-4D, 2.02258572689728E-4D, 2.72561315287353E-4D, 3.36300741790042E-4D, 4.00845175023879E-4D, 4.59227877785015E-4D, 5.1729620911614E-4D, 5.69590780355754E-4D, 6.20928846705191E-4D, 6.66784641103747E-4D, 7.11117897876378E-4D, 7.50166173221365E-4D, 7.8737089428539E-4D, 8.2073414158823E-4D, 8.52364630674893E-4D, 8.78031076317816E-4D, 9.04056377730812E-4D, 9.25316284579598E-4D, 9.44617219923473E-4D, 9.60406141450635E-4D, 9.74759111683958E-4D, 9.8556811727289E-4D, 9.94844991789253E-4D, 0.00100065530537616D, 0.00100502904982186D, 0.00100617210221234D, 0.00100598820112366D, 0.00100268670736766D, 9.98045343290508E-4D, 9.9037312341015E-4D, 9.8146855754746E-4D, 9.69697411452199E-4D, 9.5643797019856E-4D, 9.40715897598692E-4D, 0.0240815539286682D};
        syncRoot = new Object();
        arrayLength = 4096;
        rawMax = 10000.0F;
        scaleRate =  PicPosization.HeartMapH / (2.0F * rawMax);
        array = new float[arrayLength];
        quiteArray = new float[arrayLength];
    }

    public RawDataArray() {
    }

    private static float applyFilter_hpf(float[] var0) {
        int var1 = var0.length;
        float var2 = 0.0F;

        for(int var3 = 0; var3 < var1; ++var3) {
            var2 = (float)((double)var2 + (double)var0[var3] * filt_coeff_hpf[var3]);
        }

        return var2;
    }

    private static float applyFilter_lpf(float[] var0) {
        int var1 = var0.length;
        float var2 = 0.0F;

        for(int var3 = 0; var3 < var1; ++var3) {
            var2 = (float)((double)var2 + (double)var0[var3] * filt_coeff_lpf[var3]);
        }

        return var2;
    }

    private static void egoRawDataBeQuite() {
        float var0 = 0.0F;

        for(int var1 = 1; var1 <= -1 + arrayLength; var1 += 4) {
            var0 += array[var1];
        }

        float var2 = (var0 + array[-1 + arrayLength]) / (float)(1 + arrayLength / 4);

        for(int var3 = 0; var3 <= -1 + arrayLength; ++var3) {
            if(var3 % 2 == 0) {
                quiteArray[var3] = array[var3];
            } else {
                float var4 = array[var3] - var2 + baseLine;
                if(var4 > bottomBorde) {
                    var4 = bottomBorde;
                }

                if(var4 < topBorde) {
                    var4 = topBorde;
                }
                quiteArray[var3] = var4;
            }
        }

    }

    public static void generateRawDataPosizationArray() {
        for(int var0 = 5; var0 <=  arrayLength-1; ++var0) {
            if(var0 % 2 != 0) {
                array[var0 - 4] = array[var0];
            }
        }

        array[-3 + arrayLength] = array[-1 + arrayLength];
        egoRawData = baseLine - (new Float((float)rawData)).floatValue() * scaleRate;
        System.arraycopy(eegBuffer_lpf, 1, tempeegBuffer_lpf, 0, -1 + BUFFER_SIZE_LPF);
        tempeegBuffer_lpf[-1 + BUFFER_SIZE_LPF] = egoRawData;
        System.arraycopy(tempeegBuffer_lpf, 0, eegBuffer_lpf, 0, BUFFER_SIZE_LPF);
        ++bufferCounter;
        if(bufferCounter >= BUFFER_SIZE_LPF) {
            filtered = applyFilter_lpf(eegBuffer_lpf);
            System.arraycopy(eegBuffer_hpf, 1, tempeegBuffer_hpf, 0, -1 + BUFFER_SIZE_HPF);
            tempeegBuffer_hpf[-1 + BUFFER_SIZE_HPF] = filtered;
            System.arraycopy(tempeegBuffer_hpf, 0, eegBuffer_hpf, 0, BUFFER_SIZE_HPF);
            filtered = applyFilter_hpf(eegBuffer_hpf);
            array[-1 + arrayLength] = filtered;
            bufferCounter = -1 + BUFFER_SIZE_LPF;
        } else {
            array[-1 + arrayLength] = egoRawData;
        }
        egoRawDataBeQuite();
    }

    public static float[] getRawDataPosizationArray() {
        return quiteArray;
    }

    public static void initArray() {
        float var0 = 4.0F * (new Float((float)PicPosization.w)).floatValue() / (float)arrayLength;
        float var1 = var0;
        int var2 = 0;

        for(int var3 = 0; var3 <= -1 + arrayLength; ++var3) {
            array[0] = 0.0F;
            if(var3 % 2 == 0 && var3 != 0) {
                if(var2 < 2) {
                    array[var3] = var1;
                    ++var2;
                } else {
                    var1 += var0;
                    array[var3] = var1;
                    var2 = 1;
                }
            } else {
                array[var3] = baseLine;
            }
        }

        egoRawDataBeQuite();
    }

    public static void initHeartMap() {
        topBorde = PicPosization.HeartMapY;
        bottomBorde = PicPosization.HeartMapY + PicPosization.HeartMapH;
        baseLine = PicPosization.HeartMapY + PicPosization.HeartMapH / 2.0F;
    }
}
